package com.qf.qfleadnewscommons.security;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SecurityScanProperties.class)
@ConditionalOnProperty(value = "scan.enable",havingValue = "true")
public class SecurityScanAutoConfiguration {

    @Autowired
    private SecurityScanProperties properties;

    @Bean
    public IAcsClient iAcsClient(){
        IClientProfile profile = DefaultProfile
                .getProfile("cn-shanghai", properties.getAccessKeyId(), properties.getSecret());
        DefaultProfile
                .addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new IAcsClientAdapter(profile);
        return client;
    }

    @Bean
    public SecurityScanOperator securityScanOperator(IAcsClient client){
        return new SecurityScanOperator(client,properties);
    }


}
